package cn.bgs.service.impl;

import cn.bgs.mapper.CellMapper;
import cn.bgs.pojo.Building;
import cn.bgs.pojo.Cell;
import cn.bgs.pojo.CellIntermediate;
import cn.bgs.service.ICellService;
import cn.bgs.vo.UserVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 单元表 服务实现类
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@Service
public class CellServiceImpl extends ServiceImpl<CellMapper, Cell> implements ICellService {

    @Autowired
    CellMapper cellMapper;

    @Override
    public List<Cell> appFindCell(Integer buildingId) {
        QueryWrapper<Cell> wrapper = new QueryWrapper<>();

        wrapper.eq("building_id",buildingId);
        return list(wrapper);
    }

    @Override
    public void updatePc(CellIntermediate forms) {
        this.cellMapper.updatePc(forms);

    }



    @Override
    public List<CellIntermediate> loadPc(Integer id) {
        List<CellIntermediate> cellIntermediates = this.cellMapper.loadPc(id);
        return cellIntermediates;
    }

    @Override
    public void delPc(Integer id) {
        this.cellMapper.delPc(id);
    }

    @Override
    public PageInfo<CellIntermediate> findCellPc(String communityId, String identity, Integer middleState, Integer pagesize, Integer pagenow) {
        if (pagenow == null) {
            pagenow = 1;
        }

        if (pagesize == null) {
            pagesize = 5;
        }
        PageHelper.startPage(pagenow,pagesize);
        List<CellIntermediate> findCellPc= this.cellMapper.findCellPc(communityId,identity,middleState);
        PageInfo<CellIntermediate> a = new PageInfo(findCellPc);
        return a;
    }

    @Override
    public void addUserPc(UserVo forms) {
        this.cellMapper.addUserPc(forms);
        String middleId = forms.getMiddleId();
        Integer userId = forms.getUserId();
        this.cellMapper.addcell(userId,middleId);
    }


}
